﻿@model  Model.PageRole
@{
    ViewBag.Title = "数据源表列表信息";
    Layout = "~/Views/Shared/_Main.cshtml";
}
@section Head{
    <script type="text/javascript">
        var UrlArray = $.getUrlArray();
        var pageRole = '@Model.role';
        function ButtonSearch(p) {
            var v = $.trim($("#txtName").val());
            var n = $.trim($("#ddlSourceType").val());
            var c = $.trim($("#txt_Contact").val());
            var postUrl = "/SystemConfiguration/EtlSourceList/?name=" + encodeURI(v) + "&sourceType=" + encodeURI(n) + "&contact=" + encodeURI(c) + "&dbName=" + encodeURI(UrlArray["dbName"]);
            if (p == 1)
                thisPageNum = 1;
            InitList(postUrl);
        }
        function AddItem() {
            var url = "/SystemConfiguration/EtlSourceAdd?dbName=" + encodeURI(UrlArray["dbName"]);
            if (UrlArray["DBType"] == "2")
                url += "&DBType=" + UrlArray["DBType"];
            window.location.href = url;
        }
        function EditItem(v) {
            var url = "/SystemConfiguration/EtlSourceAdd/?systemID=" + v + "&dbName=" + encodeURI(UrlArray["dbName"]);
            if (UrlArray["DBType"] == "2")
                url += "&DBType=" + UrlArray["DBType"];
            window.location.href = url;
        }
        function EtlSourceViewConfig(v) {
            var url = "/SystemConfiguration/EtlSourceViewConfig/?systemID=" + v + "&dbName=" + encodeURI(UrlArray["dbName"]);
            if (UrlArray["DBType"] == "2")
                url += "&DBType=" + UrlArray["DBType"];
            window.location.href = url;
        }
        function DeleteItem(v) {
            if (confirm("确定要删除吗?")) {
                $.post("/SystemConfiguration/DeleteItem/?systemID=" + v + "&dbName=" + encodeURI(UrlArray["dbName"]), function (res) {
                    if (res != "OK")
                        alert(res);
                    else {
                        alert("操作成功！");
                    }
                    ButtonSearch();
                });
            } else
                ButtonSearch();
        }
        var opts = {
            rows: 15,
            height: 400,
            url: "",
            para: {},
            idField: "GUID",
            checkbox: false,
            rownumbers: true,
            columns: [
                    { field: 'SourceSysName', title: '系统名称', width: 23, sortable: true,
                        formatter: function (value, rowData, rowIndex) {
                            return "<a href='/SystemConfiguration/EtlSourceViewConfig/?systemID=" + rowData.GUID + dbUrl + "&dbName=" + encodeURI(UrlArray["dbName"]) + "'>" + value + "</a>";
                        }
                    },
                    { field: 'SourceTypeStr', title: '数据库类型', width: 10, align: 'center', sortable: true },
                    { field: 'SourceSysDescription', title: '描述', width: 25, sortable: true },
                    { field: 'StatusStr', title: '状态', width: 5, align: 'center', sortable: true },
                    { field: 'ETLStatus', title: '任务状态', width: 8, align: 'center',
                        formatter: function (value, rowData, rowIndex) {
                            if (value == 2)
                                return "<img src='/images/stepok.png' />";
                            else
                                return "<img src='/images/steperr.png' />";
                        }
                    },
                    { field: 'CreateTime', title: '创建时间', width: 8, align: 'center', sortable: true },
                    { field: 'list_action', title: '操作', width: 10, align: 'center',
                        formatter: function (value, rowData, rowIndex) {
                            var a = "<select onchange='DoAction(this.options.selectedIndex,\"" + rowData.GUID
                            + "\")' style='width: 100px; '><option value=''>-请选择-</option>";
                            if (pageRole == '2')
                                return a + "<option>修改</option><option>删除</option><option>跟踪</option></select>";
                            else
                                return a + "<option>跟踪</option></select>";
                        }
                    }
                ]
        };
        var dbUrl = "";
        function InitList(postUrl) {
            if (typeof (postUrl) == "undefined" || postUrl.length == 0) {
                postUrl = "/SystemConfiguration/EtlSourceList?dbName=" + encodeURI(UrlArray["dbName"]);
            }
            if (UrlArray["DBType"] == "2")
                dbUrl += "&DBType=" + UrlArray["DBType"];
            opts.url = postUrl;
            $("#DataGrid").dg(opts);
        }
        function BindDropwown() {
            $.post("/SystemConfiguration/BindDropwown", { keyName: 'SourceType', dbName: encodeURI(UrlArray["dbName"]) }, function (result) {
                var arr_sel = new Array();
                arr_sel.push("<option value='0'  >--全部--</option>");
                if (result.length > 0) {
                    for (var i = 0; i < result.length; i++) {
                        arr_sel.push("<option value='");
                        arr_sel.push(result[i].Value);
                        arr_sel.push("'>");
                        arr_sel.push(result[i].Name);
                        arr_sel.push("</option>");
                    }
                    $("#ddlSourceType").append(arr_sel.join(""));
                }
            });
        }
        //“操作”下拉框事件
        function DoAction(i, value) {
            if (pageRole == '1') {
                i = i + 2;
            }
            switch (i) {
                case 1:
                    EditItem(value);
                    break;
                case 2:
                    DeleteItem(value);
                    break;
                case 3:
                    GetPath(value, 'source', 1);
                    ButtonSearch();
                    break;
            }
        }
        $(function () {
            InitList();
            BindDropwown();
        }); 
    </script>
}
<div style="margin: 5px;">
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/search.png" />
            </td>
            <td width="300">
                源系统列表搜索
            </td>
            <td align="right">
            </td>
        </tr>
    </table>
    <table class="searchArea" width="100%">
        <tr>
            <td>
                名称：
                <input id="txtName" type="text" class="inputSearch" style="width: 200px;" />
                数据库类型：
                <select id="ddlSourceType" name="SourceType" style="width: 120px;">
                </select>
                联系人用户名：
                <input id="txt_Contact" type="text" class="inputSearch" style="width: 200px;" />
                <input type="button" class="button" value="搜索" onclick="ButtonSearch(1)" />
            </td>
            <td>
            </td>
        </tr>
    </table>
</div>
<div style="margin: 5px;">
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/filesave.png" />
            </td>
            <td width="300">
                源系统列表
            </td>
            <td align="right">
                @if (Model.role == 2)
                { 
                    <input type="button" value=" 新增 " class="button" onclick="AddItem()" />
                }
            </td>
        </tr>
    </table>
    <table id="DataGrid" class="pagTable" cellpadding="0" cellspacing="0">
    </table>
    <div>
        <div id="Pagination" class="pagination">
        </div>
        <div id="loading" class="loading">
            <img src="/Images/tree_loading.gif" />
        </div>
    </div>
    <div id="msg">
    </div>
</div>
